﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Data.SqlClient;

namespace SQLDataProviders
{
    [Serializable()]
    [DefaultProperty("Server")]
    public class GmdDataProviderConfig : INotifyPropertyChanged
    {
        #region const
        const string DefaultConnectionString = "Data Source=r710sqljahu;Initial Catalog=GMD;Integrated Security=True;Connect Timeout=120;Application Name=Xeml Designer";
        const string DefaultServer = "r710sqljahu.mpimp-golm.mpg.de";
        const string DefaultDataBase = "GMD";
        #endregion const

        #region constructor
        public GmdDataProviderConfig()
        {
            //#if DEBUG
            Server = DefaultServer;
            DataBase = DefaultDataBase;
            WindowsAuthentication = true;
            //#endif
        }
        #endregion constructor

        private string _Server;
        [Category("database connection")
                , Description("The name of the server where the data are located.")
                , ReadOnly(false)
                , DisplayName("server name")
                , DefaultValue(DefaultServer)]
        public string Server
        {
            get { return _Server; }
            set
            {
                if (value != _Server) //check whether the new value differs from the old value 
                {
                    _Server = value; //set the value to member variable 
                    OnPropertyChanged("Server"); //fire event to inform possible subscriber about the changed property 
                }
            }
        }

        private string _DataBase;
        [Category("database connection")
                , Description("The name of the database.")
                , ReadOnly(false)
                , DisplayName("database name")
                , DefaultValue(DefaultDataBase)]
        public string DataBase
        {
            get { return _DataBase; }
            set
            {
                if (value != _DataBase) //check whether the new value differs from the old value 
                {
                    _DataBase = value; //set the value to member variable 
                    OnPropertyChanged("DataBase"); //fire event to inform possible subscriber about the changed property 
                }
            }
        }

        private bool _WinAuth = false;
        [Category("database connection")
                , Description("Indicates whether or not the integrated windows authentication is used.")
                , ReadOnly(false)
                , DisplayName("Windows Authentication")
                , DefaultValue("true")]
        public bool WindowsAuthentication
        {
            get { return _WinAuth; }
            set
            {
                if (value != _WinAuth)
                {
                    _WinAuth = value;
                    OnPropertyChanged("WinAut");
                }
            }
        }

        public string ConnectionString
        {
            get
            {
                return DefaultConnectionString;
            }
        }
        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// fires the property changed evetn of an given property name
        /// </summary>
        protected virtual void OnPropertyChanged(string propName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
            }
        }
        #endregion INotifyPropertyChanged
    }
}
